package com.tsin.usercenter.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.api.RedissonReactiveClient;
import org.redisson.api.RedissonRxClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;

@ConfigurationProperties(prefix = "spring.data.redis")
@Component
@Data
public class RedissonConfig {

    private String host;
    private String port;
    private int database;


    @Bean
    public RedissonClient redissonClient(){
        // 1. 创建配置
        Config config = new Config();
        String redisUrl = String.format("redis://%s:%s", host, port);
        config.useSingleServer().setAddress(redisUrl).setDatabase(3).setPassword("518518");
        // 2. 创建实例
        // Sync and Async API
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
